package com.homegoods.orderinfodetail.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.holder.Holder;
import com.homegoods.orderinfodetail.R;
import com.homegoods.orderinfodetail.model.BannerGoodsBean;
import com.kedll.library.util.BindingUtil;
import com.kedll.library.util.ViewUtil;

import cn.jzvd.Jzvd;
import cn.jzvd.JzvdStd;

/**
 * 轮播图适配器
 * @author QiQi
 */
public class BannerAdapter implements Holder<BannerGoodsBean> {
    private ImageView bannerImg;
    private JzvdStd videoPlayer;


    {
        Jzvd.setVideoImageDisplayType(Jzvd.VIDEO_IMAGE_DISPLAY_TYPE_ORIGINAL);
    }

    @Override
    public View createView(final Context context) {
        View rootView = LayoutInflater.from(context).inflate(R.layout.info_item_recommend, null);
        bannerImg = rootView.findViewById(R.id.banner_pic);
        videoPlayer = rootView.findViewById(R.id.video_player);
        return rootView;
    }

    @Override
    public void updateUI(Context context, int position, BannerGoodsBean data) {
        if (data.getIsVideo() == 0) {
            videoPlayer.setUp(data.getUrl(), "", Jzvd.SCREEN_WINDOW_LIST);
            ViewUtil.setGone(videoPlayer.fullscreenButton, true);
            ViewUtil.setGone(bannerImg, true);
            ViewUtil.setGone(videoPlayer, false);
            BindingUtil.loadImageNoTransform(videoPlayer.thumbImageView, data.getThumb(), null, null);
        } else {
            BindingUtil.loadImageNoTransform(bannerImg, data.getUrl(), null, null);
            ViewUtil.setGone(videoPlayer, true);
            ViewUtil.setGone(bannerImg, false);
        }
    }

}
